package com.fdb.efp.nls.api.rest;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.fdb.basic.framework.core.constant.ResponseData;
import com.fdb.basic.framework.core.util.StringUtil;
import com.fdb.basic.framework.web.controller.AbstractController;
import com.fdb.efp.nls.service.facade.LoanRepayDetailService;
import com.fdb.efp.nls.service.facade.LoanRepayPlanService;
import com.fdb.efp.loan.service.vo.LoanRepayDetailVO;
import com.fdb.efp.loan.service.vo.LoanRepayPlanVO;

/**
  * 还款明细
  * @author qiuyf
  * @since 2019年2月16日 下午4:01:26
  * @version 1.0
 */
@RestController
@RequestMapping("/api")
public class LoanRepayDetailController extends AbstractController {

	@Autowired  
	@Qualifier("loanRepayDetailService")
	private LoanRepayDetailService loanRepayDetailService;
	
	@Autowired
	@Qualifier("accLoanRepayPlanService")
	private LoanRepayPlanService accLoanRepayPlanService;
	
	@RequestMapping(value = "/loan/repay/detail", method = RequestMethod.POST)
	public @ResponseBody ResponseData<List<LoanRepayDetailVO>> queryLoanRepayDetail(@RequestBody LoanRepayDetailVO vo) {
		List<LoanRepayDetailVO> outputVo = loanRepayDetailService.queryAllByLoanNoByPage(vo);
		/**
		 * 通过借据号查询还款计划信息，来获取“计划还款日”
		 */
		LoanRepayPlanVO domainVo = new LoanRepayPlanVO();
		domainVo.setRefNbr(vo.getLoanNo());
		List<LoanRepayPlanVO> result = accLoanRepayPlanService.qryLoanRepayPlanByLoanNo(domainVo);
		outputVo.forEach(out -> {
			out.setPrdName(vo.getPrdName());
			result.forEach(res ->{
				String temp = String.valueOf(res.getTerm());
				if(StringUtil.isNotEmpty(temp) && StringUtil.isNotEmpty(out.getRepayTerm()) && temp.equals(out.getRepayTerm())) {
					out.setStmtDate(res.getStmtDate());
				}
			});
		});
		return getResponseData(outputVo);

	}
	
}
